@extends('admin.main')

@section('body')
    <!-- 标题栏 -->
    <div class="main-title">
        <h2>管理员列表</h2>
    </div>
    <div class="cf">
        <div class="fl">
            <a class="btn" href="{{urlAdmin('admin','getAdd')}}">新 增</a>
            <button class="btn ajax-post" url="{{urlAdmin('admin','anyChangeStatus',['method'=>'resume'])}}"
                    target-form="ids">启 用
            </button>
            <button class="btn ajax-post" url="{{urlAdmin('admin','anyChangeStatus',['method'=>'forbid'])}}"
                    target-form="ids">禁 用
            </button>
            <button class="btn ajax-post confirm" url="{{urlAdmin('admin','anyChangeStatus',['method'=>'delete'])}}"
                    target-form="ids">删 除
            </button>
        </div>

        <!-- 高级搜索 -->
        <div class="search-form fr cf">
            <div class="sleft">
                <input type="text" name="nickname" class="search-input" value="{{session('admin')['nickname']}}"
                       placeholder="请输入用户昵称或者ID">
                <a class="sch-btn" href="javascript:;" id="search" url="{{urlAdmin('admin','getIndex')}}"><i
                            class="btn-search"></i></a>
            </div>
        </div>
    </div>
    <!-- 数据列表 -->
    <div class="data-table table-striped">
        <table class="">
            <thead>
            <tr>
                <th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>
                <th class="">ID</th>
                <th class="">昵称</th>
                <th class="">登录次数</th>
                <th class="">最后登录时间</th>
                <th class="">最后登录IP</th>
                <th class="">状态</th>
                <th class="">操作</th>
            </tr>
            </thead>
            <tbody>
            @if(count($rows['data']))
                @foreach($rows['data'] as $v)
                    <tr>
                        <td><input class="ids" type="checkbox" name="ids[]" value="{{$v['id']}}"/></td>
                        <td>{{$v['id']}}</td>
                        <td>{{$v['nickname']}}</td>
                        <td>{{$v['login']}}</td>
                        <td><span>{{$v['last_login_time'] ? date('Y-m-d H:i:s',$v['last_login_time']) : ''}}</span></td>
                        <td><span>{{$v['last_login_ip']}}</span></td>
                        <td>{{$v['status_text']}}</td>
                        <td>
                            @if($v['status'] == 1)
                                <a href="{{urlAdmin('admin','anyChangeStatus',['method'=>'forbid','ids'=>$v['id']])}}"
                                   class="ajax-get">禁用</a>
                                @else
                                <a href="{{urlAdmin('admin','anyChangeStatus',['method'=>'resume','ids'=>$v['id']])}}"
                                   class="ajax-get">启用</a>
                            @endif
                            {{--<a href="{{urlAdmin('auth','getGroup',['id'=>$v['id']],2)}}" class="authorize">授权</a>--}}
                            <a href="{{urlAdmin('admin','anyChangeStatus',['method'=>'delete','ids'=>$v['id']])}}"
                               class="confirm ajax-get">删除</a>
                        </td>
                    </tr>
                @endforeach
            @else
                <td colspan="8" class="text-center"> aOh! 暂时还没有内容!</td>
            @endif
            </tbody>
        </table>
    </div>
    <div class="page">
        @if($rows['last_page']>1)
            <div>
                @if($rows['prev_page_url'])
                    <a class="prev" href="{{$rows['prev_page_url']}}">&lt;&lt;</a>
                @endif
                @if(count($rows['pageNoList']))
                    @foreach($rows['pageNoList'] as $v)
                        @if($rows['current_page'] == $v)
                            <span class="current">{{$v}}</span>
                        @else
                            <a class="num" href="{{urlAdmin('admin','getIndex',['page'=>$v])}}">{{$v}}</a>
                        @endif
                    @endforeach
                @endif
                @if($rows['next_page_url'])
                    <a class="next" href="{{$rows['next_page_url']}}">&gt;&gt;</a>
                @endif
                <span class="rows">共 {{$rows['total']}} 条记录</span>
            </div>
        @endif
    </div>
@endsection

@section('script')
    <script src="/static/thinkbox/jquery.thinkbox.js"></script>

    <script type="text/javascript">
        //搜索功能
        $("#search").click(function () {
            var url = $(this).attr('url');
            var query = $('.search-form').find('input').serialize();
            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
            query = query.replace(/^&/g, '');
            if (url.indexOf('?') > 0) {
                url += '&' + query;
            } else {
                url += '?' + query;
            }
            window.location.href = url;
        });
        //回车搜索
        $(".search-input").keyup(function (e) {
            if (e.keyCode === 13) {
                $("#search").click();
                return false;
            }
        });
    </script>
@endsection
